package cn.xm.org.controller;


import cn.xm.basic.anno.LogAnno;
import cn.xm.basic.util.AjaxResult;
import cn.xm.basic.util.PageList;
import cn.xm.org.domain.SystemDictionaryDetail;
import cn.xm.org.domain.SystemDictionaryType;
import cn.xm.org.query.SystemDictionaryDetailQuery;
import cn.xm.org.service.SystemDictionaryDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dicdetail")
@Api(value = "部门的API",description="部门相关的CRUD功能")
public class SystemDictionaryDetailController {

    @Autowired
    private SystemDictionaryDetailService systemDictionaryDetailService;

    @PutMapping
    @ApiOperation(value = "增加或修改部门" )
    public AjaxResult addOrUpdate(@ApiParam(value="部门实体类",required = true) @RequestBody SystemDictionaryDetail systemDictionaryDetail) {
        if (systemDictionaryDetail.getId() == null) {
            systemDictionaryDetailService.add(systemDictionaryDetail);
        } else {
            systemDictionaryDetailService.update(systemDictionaryDetail);
        }
        return AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "通过ID删除" )
    public AjaxResult delete(@ApiParam(value="ID属性",required = true) @PathVariable("id") Long id) {
        systemDictionaryDetailService.delete(id);
        return AjaxResult.me().success();
    }

    @PatchMapping
    @ApiOperation(value = "批量删除" )
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
        systemDictionaryDetailService.batchDelete(ids);
        return AjaxResult.me().success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询" )
    public SystemDictionaryDetail findById(@ApiParam(value="ID属性",required = true) @PathVariable("id") Long id) {
        SystemDictionaryDetail systemDictionaryDetail = systemDictionaryDetailService.findById(id);
        return systemDictionaryDetail;
    }

    @GetMapping
    @ApiOperation(value = "查询所有" )
    public List<SystemDictionaryDetail> findAll() {
        return systemDictionaryDetailService.findAll();
    }

    @PostMapping
    @ApiOperation(value = "分页查询" )
    @LogAnno(method = "queryByPage",methodDes = "分页查询")
    public PageList<SystemDictionaryDetail> queryByPage(@ApiParam(value="分页条件封装的类",required = true) @RequestBody SystemDictionaryDetailQuery systemDictionaryDetailQuery) {
        return systemDictionaryDetailService.queryByPage(systemDictionaryDetailQuery);
    }

    @GetMapping("/type/{id}")
    @ApiOperation(value = "通过ID查询" )
    public List<SystemDictionaryDetail> findByTypeId(@ApiParam(value="ID属性",required = true) @PathVariable("id") Long id) {
        return systemDictionaryDetailService.findByTypesId(id);
    }
}
